package com.cuput.partybuilding.contact;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.cuput.partybuilding.contact.adapter.ContactFunctionsAdapter;
import com.cuput.partybuilding.contact.bean.FunctionInfo;
import com.cuput.partybuilding.contact.presenter.ContactPresenter;
import com.cuput.partybuilding.publiclibrary.base.BaseActivity;
import com.cuput.partybuilding.publiclibrary.util.Utils;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by wei on 2017-05-10.
 * 联系人功能页Activity
 */

public class ContactActivity extends BaseActivity<ContactPresenter> {
    private LinearLayout searchBar;
    private ListView functionsListView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact);
        initView();
        initListener();
    }

    private void initView() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        searchBar = (LinearLayout) findViewById(R.id.searchBar);
        GradientDrawable searchBarTvDraw = (GradientDrawable) searchBar.getBackground();
        searchBarTvDraw.setColor(getResources().getColor(R.color.colorSearchBarBg));

        functionsListView = (ListView) findViewById(R.id.functions);
        ContactFunctionsAdapter contactFunctionsAdapter = new ContactFunctionsAdapter(this, getFunctionInfos());
        functionsListView.setAdapter(contactFunctionsAdapter);
        functionsListView.setDivider(null);
        Utils.setListViewHeightBasedOnChildren(functionsListView);
    }

    private void initListener() {
        functionsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 1) {
                    Intent intent = new Intent(getBaseContext(), ContactListActivity.class);
                    startActivity(intent);
                }
            }
        });
    }

    private ArrayList<FunctionInfo> getFunctionInfos() {
        ArrayList<FunctionInfo> functionInfos = new ArrayList<FunctionInfo>() {{
            add(new FunctionInfo(R.color.colorItem5, R.drawable.icon_account, getResources().getString(R.string.my_friends)));
            add(new FunctionInfo(R.color.colorItem6, R.drawable.icon_contact_information, getResources().getString(R.string.phone_directory)));
            add(new FunctionInfo(R.color.colorItem7, R.drawable.icon_group, getResources().getString(R.string.my_group)));
        }};
        return functionInfos;
    }

    @Override
    public ContactPresenter getPresenter() {
        return new ContactPresenter(this);
    }
}
